package views;

import views.panels.PanelGeneral;
import logicBusiness.UsuarioBL;
import models.Usuario;
import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

/**
 *
 * @author JARR
 */
public class InterfazCambiarContrasena extends javax.swing.JFrame {

    private Usuario sesion;
    private ImageIcon icono;

    /** Creates new form InterfazCambiarContrasena */
    public InterfazCambiarContrasena() {
        initComponents();
        PanelGeneral panel = new PanelGeneral();
        this.add(panel, BorderLayout.EAST);
        icono = new ImageIcon(getClass().getResource("/Imagenes/icon.gif"));
        this.setIconImage(icono.getImage());
    }

    public void setSesion(Usuario sesion) {
        this.sesion = sesion;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        PFContrasenaActual = new javax.swing.JPasswordField();
        jLabel2 = new javax.swing.JLabel();
        PFContrasenaNueva = new javax.swing.JPasswordField();
        jLabel3 = new javax.swing.JLabel();
        PFConfirmarContrasena = new javax.swing.JPasswordField();
        BAceptar = new javax.swing.JButton();
        BRegresar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabel1.setText("Contraseña Actual:");

        jLabel2.setText("Contraseña Nueva:");

        jLabel3.setText("Confirmar Contraseña:");

        BAceptar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BAceptar.setText("Aceptar");
        BAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BAceptarActionPerformed(evt);
            }
        });

        BRegresar.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BRegresar.setText("Regresar");
        BRegresar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BRegresarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3))
                        .addGap(22, 22, 22)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(PFConfirmarContrasena)
                            .addComponent(PFContrasenaNueva)
                            .addComponent(PFContrasenaActual, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(83, 83, 83)
                        .addComponent(BAceptar, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(96, 96, 96)
                        .addComponent(BRegresar, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(66, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(PFContrasenaActual, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(PFContrasenaNueva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(PFConfirmarContrasena, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(38, 38, 38)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BAceptar)
                    .addComponent(BRegresar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BAceptarActionPerformed
        int error = 0;
        if (String.valueOf(PFContrasenaActual.getPassword()).equals("") || String.valueOf(PFContrasenaNueva.getPassword()).equals("") || String.valueOf(PFConfirmarContrasena.getPassword()).equals("")) {
            JOptionPane.showMessageDialog(this, "Campos vacios", null, JOptionPane.ERROR_MESSAGE);
            error = 1;
        }
        if (!String.valueOf(PFContrasenaNueva.getPassword()).equals(String.valueOf(PFConfirmarContrasena.getPassword()))) {
            JOptionPane.showMessageDialog(this, "La contraseña nueva no coincide", null, JOptionPane.ERROR_MESSAGE);
            error = 1;
        }

        if (error == 0) {
            UsuarioBL bo = new UsuarioBL();
//            Usuario u = bo.actualizarUsuario(sesion.getNombreUsuario(), String.valueOf(PFContrasenaActual.getPassword()), String.valueOf(PFContrasenaNueva.getPassword()));
//
//            if (u != null) {//si se encuentra el usuario, y s
//                if (u.getClave().equals(String.valueOf(PFContrasenaNueva.getPassword()))) {
//                    JOptionPane.showMessageDialog(this, "La contraseña se cambió exitosamente");
//                } else {
//                    JOptionPane.showMessageDialog(this, "Disculpe, intente de nuevo", "Error Cambio de Contraseña", JOptionPane.ERROR_MESSAGE);
//                }
//            } else {
//                JOptionPane.showMessageDialog(this, "Contraseña Actual Errada", "Error Datos Actual", JOptionPane.ERROR_MESSAGE);
//            }
        }


    }//GEN-LAST:event_BAceptarActionPerformed

    private void BRegresarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BRegresarActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_BRegresarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new InterfazCambiarContrasena().setVisible(true);

            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BAceptar;
    private javax.swing.JButton BRegresar;
    private javax.swing.JPasswordField PFConfirmarContrasena;
    private javax.swing.JPasswordField PFContrasenaActual;
    private javax.swing.JPasswordField PFContrasenaNueva;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration//GEN-END:variables
}
